﻿using Base.ModuleBase.Notifications;
using Prism.Interactivity.InteractionRequest;
using System;

namespace Base.ModuleBase
{
    /// <summary>
    /// 支持InteractionRequest交互(如,通过PopupWindowAction在弹出窗中显示)的ViewModel基类.
    /// </summary>
    public class PopWindowViewModelBase : ViewModelBase, IInteractionRequestAware
    {
        private INotification _notification;

        public INotification Notification
        {
            get { return _notification;}
            set
            {
                _notification = value;
                if (value != null)
                {
                    var vn = value as ViewNotification;
                    if (vn != null)
                    {
                        vn.ViewModel = this;
                    }
                }
                OnNotificationSet();
            }
        }

        /// <summary>
        /// 当Notification被设置时触发
        /// </summary>
        protected virtual void OnNotificationSet()
        {
            
        }

        /// <summary>
        /// 关闭窗口
        /// </summary>
        public Action FinishInteraction { get; set; }

        /// <summary>
        /// ViewModel外的窗口关闭请求，返回false以取消关闭
        /// </summary>
        /// <returns></returns>
        public virtual bool RequestClose()
        {
            return true;
        }

        public object Result { get; set; }

        public bool IsCanceled { get; protected set; }

    }
}
